package com.qr.dao.impl;

import com.qr.dao.IUserDao;
import com.qr.domain.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.util.List;

public class UserDaoImpl implements IUserDao {

    private SqlSessionFactory sessionFactory;

    /**
     * 初始化加载的时候就加载工厂
     * @return
     */
    public UserDaoImpl(SqlSessionFactory factory) {
        this.sessionFactory = factory;
    }

    @Override
    public List<User> findAll() {
        SqlSession sqlSession = sessionFactory.openSession();
        List<User> users = sqlSession.selectList("com.qr.dao.IUserDao.findAll");
        sqlSession.close();
        return users;
    }
}
